CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/billing/[[...page]].tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Layout } from "antd";
7
8
import { capitalize } from "@cocalc/util/misc";
9
import { MainPages, MainPagesType } from "components/billing/consts";
10
import BillingLayout from "components/billing/layout";
11
import Footer from "components/landing/footer";
12
import Head from "components/landing/head";
13
import Header from "components/landing/header";
14
import { Customize, CustomizeType } from "lib/customize";
15
import withCustomize from "lib/with-customize";
16
import Error from "next/error";
17
18
interface Props {
19
customize: CustomizeType;
20
pageNotFound: boolean;
21
page: [MainPagesType | undefined];
22
}
23
24
export default function Preferences(props: Props) {
25
const { customize, pageNotFound, page } = props;
26
27
const subpage = page?.[0] != null ? ` - ${capitalize(page[0])}` : "";
28
29
return (
30
<Customize value={customize}>
31
<Head title={`Billing${subpage}`} />
32
<Layout>
33
<Header />
34
{pageNotFound ? (
35
<Error statusCode={404} />
36
) : (
37
<BillingLayout page={page} />
38
)}
39
<Footer />
40
</Layout>
41
</Customize>
42
);
43
}
44
45
export async function getServerSideProps(context) {
46
const { params, res } = context;
47
const { page = [] } = params;
48
49
// deprecated – https://github.com/sagemathinc/cocalc/issues/5739
50
// see billing/layout.tsx for possible pages
51
const [main] = page;
52
switch (main) {
53
// 307: temp redirect
54
case "payment-methods":
55
return res.redirect(307, "./cards");
56
case "invoices-and-receipts":
57
return res.redirect(307, "./receipts");
58
}
59
60
if (main != null && !MainPages.includes(main)) {
61
return await withCustomize({ context, props: { pageNotFound: true } });
62
}
63
64
return await withCustomize({
65
context,
66
props: { page },
67
});
68
}
69
70